<?php
require_once(dirname(__FILE__) . '/inc/config.inc.php');
IsModelPriv('order');
require_once "function.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>拜访列表</title>
    <link href="templates/style/admin.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="templates/js/jquery.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="ui/css/bootstrap.min.css">
    <link rel="stylesheet" href="ui/css/bootstrap-theme.min.css">
    <!-- 最新版本的 layui 核心 CSS 文件 -->

    <link href="layui/css/layui.css" rel="stylesheet" type="text/css" media="all"/>
    <script src="layui/layui.all.js"></script>
</head>
<body>
<style>
    .layui-table-cell { /*最后的pic为字段的field*/
        height: 100%;
        max-width: 100%;
        height: auto;
        white-space: normal;
        word-wrap: break-word;
        word-break: break-all;
    }
    .layui-layout-body {
        overflow: auto;
    }
    .mt10 { margin-top: 10px;}
</style>
<div class="" >
    <div class="">
        <div class="layui-fluid">
            <div class="layui-row">
                <!-- 右表 -->
                <div class="layui-col-sm12 mt10"></div>
                <div class="layui-card layadmin-header">
                    <div class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
                        <a lay-href="">主页</a><span lay-separator="">/</span>
                        <a><cite>拜访列表</cite></a><span lay-separator="">/</span>

                    </div>
                </div>
                <div class="layui-col-sm12">

                    <div class="layui-col-sm12 " style="margin-top: 10px;">
                        <div class=" layuiadmin-card-header-auto">
                            <div class="layui-form  layuiadmin-card-header-auto" lay-filter="layadmin-userfront-formlist">
                                <div class="layui-form-item ss">

                                    <div class="layui-inline"><label class="layui-form-label">工程师</label>
                                        <div class="layui-input-block">
                                            <select name="manageid" id="manageid" lay-filter="manageid">
                                                <option value="0">请选择</option>
                                                <?php
                                                $dosql->Execute("SELECT * FROM `#@__user` WHERE `level`<5   order by id ASC", 10);
                                                while ($row = $dosql->GetArray(10)) {
                                                    echo '<option  value="' . $row['id'] . '" >' . $row['truename'] . '</option>';

                                                }
                                                ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline"><label class="layui-form-label">客户 ≈</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="school" id="school" placeholder="请输入" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">手机号</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input" name="mobile" id="mobile" autocomplete="off" value="">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">时间</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input" name="dtime" id="test-laydate-format-range2"
                                                   placeholder="开始 到 结束" autocomplete="off" value="">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit="" lay-filter="LAY-user-front-search">
                                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i></button>
                                    </div>
                                    <div class="layui-inline">
                                        <button class="layui-btn  layuiadmin-btn-useradmin layui-btn-danger" data-type="refush" lay-tips="重置搜索条件，并显示全部的用户">
                                            全部
                                        </button>
                                        <div class="layui-inline">
                                            <button class="layui-btn  layuiadmin-btn-useradmin layui-btn-warm" data-type="excel" lay-tips="点击按查询条件导出excel">
                                                <i class="layui-icon layui-icon-export"></i>导出当前查询到Excel
                                            </button>
                                        </div>
                                    </div>

                                </div>
                            </div>


                        </div>
                    </div>
                    <div class="layui-card">
                        <div class="layui-col-sm12 ">

                            <table id="member" lay-filter="member"></table>



                            <script type="text/html" id="table-list-op1">
                                <a class="layui-btn layui-btn-success layui-btn-xs" lay-event="showpic">
                                   点击查看
                                </a>

                            </script>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    layui.config({
        base: 'layui/lay/modules/'
    }).extend({
        admin: 'admin',
        view: 'view'
    }).use(['table', 'admin', 'view', 'laydate'], function () {

        //无需再执行layui.use()方法加载模块，直接使用即可
        var form = layui.form,
            layer = layui.layer,
            admin = layui.admin,
            view = layui.view,
            laydate = layui.laydate,
            table = layui.table;
        //第一个实例
        table.render({
            elem: '#member'
            , url: 'json/visit/list.php' //数据接口
            , page: true //开启分页
            , cellMinWidth: 100
            , cols:
                [[ //表头
                    {field: 'id', title: 'ID', width: 80}
                    , {field: 'manage_name', align: 'left', title: '员工',width: 100}
                    , {field: 'school', align: 'left', title: '单位',width: 180}
                    , {field: 'truename', align: 'left', title: '联系人', width: 100}
                    , {field: 'mobile', align: 'left', title: '联系方式', width: 140}
                    , {field: 'address', align: 'left', title: '地址', width: 260}
                    , {field: 'content', align: 'left', title: '拜访摘要'}
                    , {field: 'addtime', align: 'center', title: '拜访时间', width: 160}
                    , {field: 'op', title: ' 拜访照片', toolbar: '#table-list-op1', width: 100}
                ]],
            limit: 15,
            limits: [10, 15, 20, 25, 30],
            text: {none: '暂无数据'}
        });

        form.render(null, 'layadmin-userfront-formlist');


        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            field = data.field;            //执行重载
            table.reload('member', {
                where: field,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });


        //事件
        var active = {
            refush: function () {

                $("#test-laydate-format-range2").val("");
                $("#manageid").get(0).selectedIndex = 0;
                $("#task").get(0).selectedIndex = 0;
                form.render(null, 'layadmin-userfront-formlist');
                table.reload('member', {
                    where: {
                        'task': 0,
                        'manageid': 0,
                        'dtime': '',

                    },
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            }, excel: function () {
                console.log('excel开始');
                //form.render("search");
                var dtime = $("#test-laydate-format-range2").val();
                var mobile = $("#mobile").val();
                var school = $("#school").val();
                var manageid = $("#manageid").val();
                window.open('json/fee/visit2Excel.php?dtime=' + dtime + '&mobile=' + mobile + '&school=' + school+'&manageid='+mobile);
            },

        };
        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听工具条
        table.on('tool(member)', function (obj) {
            var data = obj.data;
            console.log(data)
            if (obj.event === 'showpic') {
                $.ajax({
                    url: "getPhoto.php?id=" + data.id + "&type=visit&index=0",
                    data: "",
                    type: "get",
                    dataType: "json",
                    success: function (res) {
                        if (res.msg === "ok") {
                            //登入成功的提示与跳转
                            layer.photos({
                                photos: res.data,
                                shift: 5 //0-6的选择，指定弹出图片动画类型，默认随机

                            });

                        }
                    }
                });
            }
        });

        //获取当前时间
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        var nowDate = year + "-" + month + "-" + day;
        //日期时间范围
        laydate.render({
            elem: '#test-laydate-format-range2'
            , range: '~'
            , max: nowDate
        });

    });
</script>

</body>
</html>
